package org.example.springbookdamo.Controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/user")
@RestController
public class UserController { //登录接口
    @PostMapping("/login")
    public boolean login(String name, String password , HttpSession session) {
        //1.参数校验
        //2.校验账号和密码是否正确
        //3.设置session
        //4.返回结果
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)) {
            return false;

        }//还未学习数据库，先写死这里
        if("admin".equals(name) && "password".equals(password)) {
            session.setAttribute("userName",name);
            return true;
        }
        return false;
    }
}
